/*
 * Name: Joon Ho Cho
 * Date: 10/24/2008
 * Course: 15-437
 */
package scheduler.formbean;

import java.util.ArrayList;
import java.util.List;

public class searchForm {
	private String keywords;
	private String courseName;
	private int number=-2;
	private String semester;
	private String department;
	private String instructor;
	private String description;
	private int units=-2;
	private int year;
	private String classroom;
	private String day;
	
	public String getCourseName()  { return courseName; }
	public String getKeywords()  { return keywords; }
	public int getNumber()  { return number; }
	public String getSemester()  { return semester; }
	public String getDepartment()  { return keywords; }
	public String getInstructor()  { return instructor; }
	public String getDescription()  { return description; }
	public String getClassroom()  { return classroom; }
	public String getDay()  { return day; }
	public int getUnits()  { return units; }
	public int getYear()  { return year; }
	
	public void setCourseName(String s) { courseName= s.trim();}
	public void setKeywords(String s)  {  keywords= s.trim(); }
	public void setDescription(String s)  {  description= s.trim(); }
	public void setDay(String s)  {  day= s.trim(); }
	public void setNumber(String s)throws Exception  {  
		try{
			number= Integer.parseInt(s.trim());
			
		}
		catch(Exception e){
			
			number= -1;
		}
		
		}
	public void setSemester(String s)  {  semester= s.trim(); }
	public void setClassroom(String s)  {  classroom= s.trim(); }
	public void setDepartment(String s)  {  keywords= s.trim(); }
	public void setInstructor(String s)  {  instructor= s.trim(); }
	public void setUnits(String s)throws Exception  {  
		try{
			units= Integer.parseInt(s.trim());
			
		}
		catch(Exception e){
			units= -1;
			
		}
		
		}
	
	public void setYear(String s)throws Exception  {  
		try{
			year= Integer.parseInt(s.trim());
			
		}
		catch(Exception e){
			year= -1;
			
		}
		
		}
	
	public List<String> getValidationErrors() {
		List<String> errors = new ArrayList<String>();

		if(units ==-1 || number ==-1){
			errors.add("Units and/or Number have to be an integer value");
		}
		
		return errors;
	}
	
	public boolean isPresent() {
		if (keywords != null) return true;
		if (semester != null) return true;
		if (department != null) return true;
		if (instructor != null) return true;
		if (number != -2) return true;
		if (units != -2) return true;
		if(courseName!=null) return true;
		return false;
	}
	
	public boolean isCourse(){
		if(courseName!=null) return true;
		if (units >0) return true;
		if (number >0) return true;
		return false;
	}
	
	public boolean isSection(){
		if (instructor != null) return true;
		return false;
	}
	

}
